﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Ahi.Controller
{
    public class EnumListeController<T>
       where T : struct,IComparable
    {
        public List<KeyValuePair<T, string>> List { get; private set; }

        private static EnumListeController<T> instance;
        public static EnumListeController<T> Instance
        {
            get
            {
                if (instance == null)
                    instance = new EnumListeController<T>();
                return instance;
            }
        }

        private EnumListeController()
        {
            Load();
        }

        private void Load()
        {
            var names = Enum.GetNames(typeof(T));
            var values = Enum.GetValues(typeof(T));

            List = new List<KeyValuePair<T, string>>();

            foreach (T item in values)
            {
                string name = Enum.GetName(typeof(T), item);
                string formattedName = Regex.Replace(name, @"((?<=\p{Ll})\p{Lu})|((?!\A)\p{Lu}(?>\p{Ll}))", " $0");
                formattedName = formattedName.Replace("__", "-");
                formattedName = formattedName.Replace("_", " ");
                List.Add(new KeyValuePair<T, string>(item, formattedName));
            }
        }
    }
}
